%GENERATEDATA Weater data set creator.
%
%   elstonj 02-20-08
function GenerateData(type,weather)
%*=+--+=#=+--      UAS Severe Weather Simulation Softeware        --+=#=+--+=#*%
%          Copyright (C) 2013 Regents of the University of Colorado.           %
%                             All Rights Reserved.                             %
%                                                                              %
%    This program is free software: you can redistribute it and/or modify      %
%    it under the terms of the GNU General Public License version 2 as         %
%    published by the Free Software Foundation.                                %
%                                                                              %
%    This program is distributed in the hope that it will be useful,           %
%    but WITHOUT ANY WARRANTY; without even the implied warranty of            %
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             %
%    GNU General Public License for more details.                              %
%                                                                              %
%    You should have received a copy of the GNU General Public License         %
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.     %
%                                                                              %
%           Jack Elston                                                        %
%           elstonj@colorado.edu                                               %
%                                                                              %
%*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*%

settings.datadir = 'data/';

switch lower(type)

  case 'vortex'
    filename = strcat(settings.datadir,'2008-06-06/DATA0');
    fid = fopen(filename, 'w');

    magnitude = 30.0; % m/s

    for i=1:19
      for j=1:19
        rain = norm([i-10,j-10])/2000;
        hail = 0.0;
        theta = atan2(j-10,i-10);
        if norm([i-10,j-10]) == 0
          u = 0.0;
          v = 0.0;
        else 
          u = magnitude * cos(theta);
          v = -magnitude * sin(theta);
        end
        w = 0.0;
        fprintf(fid,'  %f  %f  %f  %f  %f\n', rain, hail, u, v, w);
      end
    end

    fclose(fid);

  case 'flat'
    filename = strcat(settings.datadir,'2008-06-13/DATA0');
    fid = fopen(filename, 'w');

    magnitude = 30.0; % m/s

    for i=1:19
      for j=1:19
        rain = j/2800;
        hail = 0.0;
        u = -magnitude;
        v = 0.0;
        w = 0.0;
        fprintf(fid,'  %f  %f  %f  %f  %f\n', rain, hail, u, v, w);
      end
    end

    fclose(fid);

  case 'subset'
    filename = strcat(settings.datadir,'2008-09-15/DATA0');
    fid = fopen(filename, 'w');

    x0 = 1.9*10^4;
    xf = 2.7*10^4;
    y0 = 1.7*10^4;
    yf = 2.5*10^4;

    matrix = weather(4500,x0:weather.xs:xf,y0:weather.ys:yf,weather.z0);

    for i=1:size(matrix.u,1)
      for j=1:size(matrix.u,2)
        rain = matrix.rain(i,j);
        hail = matrix.hail(i,j);
        u = matrix.u(i,j);
        v = matrix.v(i,j);
        w = 0.0;
        fprintf(fid,'  %f  %f  %f  %f  %f\n', rain, hail, u, v, w);
      end
    end

    fclose(fid);

  case 'sinusoid'
    filename = strcat(settings.datadir,'2009-08-07/DATA0');
    fid = fopen(filename, 'w');

    magnitude = 30.0; % m/s

    for i=1:19
      for j=1:19
        rain = norm([i-10,j-10])/2000;
        hail = 0.0;
        if norm([i-10,j-10]) == 0
          u = 0.0;
          v = 0.0;
        else 
          u = magnitude * pi*cos(pi/10*i);
          v = magnitude*(j-10)/20;
        end
        w = 0.0;
        fprintf(fid,'  %f  %f  %f  %f  %f\n', rain, hail, u, v, w);
      end
    end

    fclose(fid);

  case 'gradient'

		simdata.prefix      = 'DATA';
		simdata.t0          = 0;
		simdata.ts          = 1;
		simdata.tf          = 0;
		simdata.xnum        = 19;
		simdata.x0          = 0;
		simdata.xs          = 1;
		simdata.ynum        = 19;
		simdata.y0          = 0;
		simdata.ys          = 1;
		simdata.znum        = 19;
		simdata.z0          = 1;
		simdata.zs          = 1;
		simdata.frame.u     = 0;
		simdata.frame.v     = 0;

	  directory = strcat(settings.datadir,type,'/');
    filename = strcat(directory,simdata.prefix,sprintf('%i',simdata.t0));
		if exist(directory) ~= 7
			mkdir(directory);
		end
    fid = fopen(filename, 'w');

    magnitude = 15.0; % m/s

		for k=1:simdata.znum
			for j=1:simdata.ynum
				for i=1:simdata.xnum
					rain = 0.0;
					hail = 0.0;
					u = magnitude * k/simdata.znum;
					v = 0.0;
					w = 0.0;
					fprintf(fid,'  %f  %f  %f  %f  %f\n', rain, hail, u, v, w);
				end
      end
    end

    fclose(fid);

		CreateParametersFile(simdata,directory);

  case default
end
